package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * key = value ->  String value = request.getParameter("key")
 */
//@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        ItemType[] values = ItemType.values();
        for (ItemType itemType : values) {
            if (source.equals(itemType.getCode()+"")){
                return itemType;
            }
        }
        throw new RuntimeException("你传的参数有问题");
    }
}
